package com.iwomy.envpro.platform.controller;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iwomy.envpro.common.core.util.R;
import com.iwomy.envpro.common.log.annotation.SysLog;
import com.iwomy.envpro.platform.entity.PlatformTelephoneConfigEntity;
import com.iwomy.envpro.platform.service.PlatformTelephoneConfigService;
import org.springframework.security.access.prepost.PreAuthorize;
import com.iwomy.envpro.common.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 平台参数-语音配置
 *
 * @author pig
 * @date 2023-11-27 14:06:26
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/platformTelephoneConfig" )
@Tag(description = "platformTelephoneConfig" , name = "平台参数-语音配置管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class PlatformTelephoneConfigController {

    private final  PlatformTelephoneConfigService platformTelephoneConfigService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param platformTelephoneConfig 平台参数-语音配置
     * @return
     */
    @Operation(summary = "分页查询" , description = "分页查询" )
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('platform_platformTelephoneConfig_view')" )
    public R getPlatformTelephoneConfigPage(@ParameterObject Page page,@ParameterObject PlatformTelephoneConfigEntity platformTelephoneConfig) {
        LambdaQueryWrapper<PlatformTelephoneConfigEntity> wrapper = Wrappers.lambdaQuery();
        return R.ok(platformTelephoneConfigService.page(page, wrapper));
    }


    /**
     * 通过id查询平台参数-语音配置
     * @param id id
     * @return R
     */
    @Operation(summary = "通过id查询" , description = "通过id查询" )
    @GetMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('platform_platformTelephoneConfig_view')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(platformTelephoneConfigService.getById(id));
    }

    /**
     * 新增平台参数-语音配置
     * @param platformTelephoneConfig 平台参数-语音配置
     * @return R
     */
    @Operation(summary = "新增平台参数-语音配置" , description = "新增平台参数-语音配置" )
    @SysLog("新增平台参数-语音配置" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('platform_platformTelephoneConfig_add')" )
    public R save(@RequestBody PlatformTelephoneConfigEntity platformTelephoneConfig) {
        return R.ok(platformTelephoneConfigService.save(platformTelephoneConfig));
    }

    /**
     * 修改平台参数-语音配置
     * @param platformTelephoneConfig 平台参数-语音配置
     * @return R
     */
    @Operation(summary = "修改平台参数-语音配置" , description = "修改平台参数-语音配置" )
    @SysLog("修改平台参数-语音配置" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('platform_platformTelephoneConfig_edit')" )
    public R updateById(@RequestBody PlatformTelephoneConfigEntity platformTelephoneConfig) {
        return R.ok(platformTelephoneConfigService.updateById(platformTelephoneConfig));
    }

    /**
     * 通过id删除平台参数-语音配置
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除平台参数-语音配置" , description = "通过id删除平台参数-语音配置" )
    @SysLog("通过id删除平台参数-语音配置" )
    @DeleteMapping
    @PreAuthorize("@pms.hasPermission('platform_platformTelephoneConfig_del')" )
    public R removeById(@RequestBody Long[] ids) {
        return R.ok(platformTelephoneConfigService.removeBatchByIds(CollUtil.toList(ids)));
    }


    /**
     * 导出excel 表格
     * @param platformTelephoneConfig 查询条件
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('platform_platformTelephoneConfig_export')" )
    public List<PlatformTelephoneConfigEntity> export(PlatformTelephoneConfigEntity platformTelephoneConfig) {
        return platformTelephoneConfigService.list(Wrappers.query(platformTelephoneConfig));
    }
}